home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW Related / MPW Script Tips 1.1.1 / Sample Scripts / LtoU < prev    next >
Encoding:
Text File  |  1991-08-16  |  2.5 KB  |  80 lines  |  [TEXT/MPS ]

  1. #----------------------------------------------------------------------------------------------------------------------------------------------------
  2. #    LtoU
  3. #    MPW Shell Script
  4. #    Written by Gina Cherry • August 16, 1991
  5. #    Copyright:    © 1991 by Apple Computer, Inc., all rights reserved.
  6. #    
  7. #    Usage: 
  8. #            LtoU [Window]
  9. #            
  10. #    Function:
  11. #            LtoU converts the selected text in the specified window from lowercase to uppercase.
  12. #
  13. #    Note: LtoU can be added to the Edit menu with the following command:
  14. #                    AddMenu Edit 'LtoU/4' 'LtoU "{Active}"'
  15. #----------------------------------------------------------------------------------------------------------------------------------------------------
  16.  
  17. # Make sure there is no more than 1 parameter.
  18.     If {#} > 1                                                            
  19.         Echo "###Usage: {0} Window"
  20.         Exit 1
  21.     End
  22.  
  23. # Do not exit on error.
  24.     Set Exit 0    
  25.  
  26. #Initialize flag variable.    
  27.     Set flag ""
  28.  
  29. # Set Window to the parameter, or to the target window if no parameter was given.
  30.     If {#} == 1                                                            
  31.         Set Window "{1}"                                            
  32.     Else                                                                        
  33.         Set Window "{Target}"
  34.     End
  35.  
  36. # Set the variable Old to the selected text in the input file.  This command has the side effect of 
  37. #    checking whether
  38. #    the window is open.  Catenate will fail if Window is not an open window.  The variable flag will be 
  39. #    set to 1 if and only if the Catenate command    is not successful.  
  40.     Begin
  41.         Set Old "`Catenate "{Window}.§" || Set flag 1 `"
  42.     End ≥ Dev:Null
  43.     
  44. #    Check if flag variable is set; if it is, write error message and exit with status 2.
  45.     If {flag}
  46.         Echo "### {0}: {Window} not a valid window."
  47.         Exit 2
  48.     End
  49.     
  50. #    If no text was selected in the input window, exit script.
  51.     Exit If "{Old}" == ""                                                                
  52.  
  53. # Otherwise, do the conversion.                                        
  54.     # Save value of NewWindowRect to restore later.
  55.         Set OldWindowRect "{NewWindowRect}"        
  56.     
  57.     # Set NewWindowRect so that new windows are small.
  58.         Set NewWindowRect 0,0,100,100
  59.     
  60.     # Open a temporary workspace.
  61.         Open -n {0}.Temp    
  62.     
  63.     # Restore value of NewWindowRect.
  64.         Set NewWindowRect "{OldWindowRect}"
  65.     
  66.     # Translate all lowercase letters in the selected text to uppercase, and redirect the output to the 
  67.     #    temporary file.
  68.         Translate a-z A-Z < "{Window}.§" > {0}.Temp    
  69.     
  70.     # Select the entire temporary file.
  71.         Find •:∞ {0}.Temp
  72.     
  73.     # Copy the selected text to the clipboard.
  74.         Copy § {0}.Temp                                            
  75.     
  76.     # Write the converted text to Window, overwriting the old version of the text.
  77.         Paste § "{Window}"
  78.     
  79.     # Close the workspace; don't save changes.
  80.         Close -n {0}.Temp